package com.huawei.hms.support.api.iap.json;

import android.app.PendingIntent;
import android.text.TextUtils;
import com.huawei.hms.common.internal.ResponseErrorCode;
import com.huawei.hms.common.internal.TaskApiCall;
import com.huawei.hms.support.api.client.Status;
import com.huawei.hms.support.api.entity.iap.IsBillingSupportedResp;
import com.huawei.hms.support.api.entity.iap.OrderStatusCode;
import com.huawei.hms.support.api.iap.IsBillingSupportedResult;
import com.huawei.hms.support.hianalytics.HiAnalyticsClient;
import com.huawei.hms.support.log.HMSLog;
import com.huawei.hms.utils.JsonUtil;
import o.fjx;

public class IsBillingSupportedTaskApiCall extends TaskApiCall<IapHmsClient, IsBillingSupportedResult> {
    public IsBillingSupportedTaskApiCall(String str, String str2) {
        super(str, JsonUtil.createJsonString(null), str2);
    }

    protected void doExecute(IapHmsClient iapHmsClient, ResponseErrorCode responseErrorCode, String str, fjx<IsBillingSupportedResult> o_fjx_com_huawei_hms_support_api_iap_IsBillingSupportedResult) {
        if (responseErrorCode == null) {
            o_fjx_com_huawei_hms_support_api_iap_IsBillingSupportedResult.ॱ(new IapApiException(new Status(1)));
            return;
        }
        HiAnalyticsClient.reportExit(iapHmsClient.getContext(), getUri(), getTransactionId(), responseErrorCode.getStatusCode(), responseErrorCode.getErrorCode());
        if (TextUtils.isEmpty(str)) {
            o_fjx_com_huawei_hms_support_api_iap_IsBillingSupportedResult.ॱ(new IapApiException(new Status(responseErrorCode.getErrorCode(), responseErrorCode.getErrorReason())));
            return;
        }
        IsBillingSupportedResp isBillingSupportedResp = new IsBillingSupportedResp();
        JsonUtil.jsonToEntity(str, isBillingSupportedResp);
        if (responseErrorCode.getErrorCode() == 0) {
            HMSLog.i("IsBillingSupportedTaskApiCall", "onResult, success");
            IsBillingSupportedResult isBillingSupportedResult = new IsBillingSupportedResult();
            isBillingSupportedResult.setReturnCode(isBillingSupportedResp.getReturnCode());
            isBillingSupportedResult.setStatus(a(responseErrorCode, isBillingSupportedResp));
            o_fjx_com_huawei_hms_support_api_iap_IsBillingSupportedResult.ॱ(isBillingSupportedResult);
        } else if (responseErrorCode.getErrorCode() == OrderStatusCode.ORDER_HWID_NOT_LOGIN) {
            o_fjx_com_huawei_hms_support_api_iap_IsBillingSupportedResult.ॱ(new IapApiException(a(responseErrorCode, isBillingSupportedResp)));
        } else {
            HMSLog.i("IsBillingSupportedTaskApiCall", "onResult, returnCode: " + responseErrorCode.getErrorCode());
            o_fjx_com_huawei_hms_support_api_iap_IsBillingSupportedResult.ॱ(new IapApiException(new Status(responseErrorCode.getErrorCode(), responseErrorCode.getErrorReason())));
        }
    }

    private static Status a(ResponseErrorCode responseErrorCode, IsBillingSupportedResp isBillingSupportedResp) {
        PendingIntent pendingIntent = null;
        if (responseErrorCode.getParcelable() instanceof PendingIntent) {
            pendingIntent = (PendingIntent) responseErrorCode.getParcelable();
        }
        return new Status(isBillingSupportedResp.getReturnCode(), "", pendingIntent);
    }
}
